What can cause the "cannot find symbol" error in Java? 您所在的位置:网站首页 cannot find symbol variable What can cause the "cannot find symbol" error in Java?

What can cause the "cannot find symbol" error in Java?

2022-06-14 11:14| 来源: 网络整理| 查看: 265

What can cause the "cannot find symbol" error in Java? JavaObject Oriented ProgrammingProgramming

The “cannot find symbol” error occurs mainly when we try to reference a variable that is not declared in the program which we are compiling, it means that the compiler doesn’t know the variable we are referring to.

Some possible causes for “Cannot find symbol” to occur areUsing a variable that is not declared or outside the code.Using wrong cases (“tutorials” and “Tutorials" are different) or making spelling mistakes.The packaged class has not been referenced correctly using an import declaration.Using improper identifier values like letters, numbers, underscore and dollar sign. The hello-class is different from helloclass.Examplepublic class CannotFindSymbolTest {    public static void main(String[] args) {       int n1 = 10;       int n2 = 20;       sum = n1 + n2;       System.out.println(sum);    } }OutputCannotFindSymbolTest.java:5: error: cannot find symbol sum = n1 + n2; ^ symbol: variable sum location: class CannotFindSymbolTest CannotFindSymbolTest.java:7: error: cannot find symbol System.out.println(sum); ^ symbol: variable sum location: class CannotFindSymbolTest

In the above program, "Cannot find symbol" error will occur because “sum” is not declared. In order to solve the error, we need to define “int sum = n1+n2” before using the variable sum.

raja Raja Published on 31-Jul-2019 19:10:44 Related Questions & AnswersWhat can cause a Cannot find symbol error in java? What is "Processing Symbol Files" message in Xcode? Why "this" keyword cannot be used in the main method of java class? What is JSlint error "missing radix parameter" in JavaScript? What is the class "class" in Java? What is the importance of "Java.lang.Class" in Java? What's the difference between "!!" and "?" in Kotlin? What is the difference between "var" and "val" in Kotlin? What is the difference between "const" and "val" in Kotlin? Linux – How to resolve the error "can't connect to Docker daemon" Java regex program to match parenthesis "(" or, ")". What is the difference between "std::endl" and "\n" in C++? What's the difference between "update" and "update_idletasks" in Tkinter? DecimalFormat("000000E0") in Java DecimalFormat("00.00E0") in Java

Previous Page Print Page Next Page   Advertisements


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有